var phoneWin = null;
var ringtone = null;
var hangupSound = null;
var ringbacktone = null;
var accountId = "";
var seatType = 1;

var ringtone = null;
var ringbacktone = null;
var callCenter = null;
var seatStatus = 0; // 0-未分配坐席;1-未登录;2-空闲;3-呼出;4-呼入;5-接通
var seatExpire = 0;
var loginErrorCount = 0;

// 话机状态
// ____________________________
// | 对方超时未接听或拒绝 v
// INVALID ---> IDLE ---> RINGING ---> ACCEPTED ---> TERMINATED
// | ^
// ------主动提前挂机或呼叫失败------------|
var PHONE_STATE = {
	INVALID : -1, // 不可用，还未注册到语音交换服务器
	IDLE : 0, // 空闲，等待呼入和呼出
	RINGING : 1, // 振铃，呼入振铃或呼出振铃中
	ACCEPTED : 2, // 已接通，呼入或呼出双方已接通
	TERMINATED : 3
// 电话挂断，呼出未接通提前挂断、呼出失败或接通后正常结束
};

// 会话方向
var SESSION_DIRECTION = {
	INVALID : -1, // 无效
	INBOUND : 0, // 呼入
	OUTBOUND : 1
// 呼出
};

var SESSION_END_REASON = {
	NORMAL : "Normal", // 正常通话挂断
	CANCEL : "Cancel", // 外呼接通前主动挂断
	INVALID_NUMBER : "Invalid_number", // 空号
	UNAVAILABLE : "Unavailable", // 暂时无法接通
	BUSY : "Busy", // 用户忙，超时未接听
	REJECTED : "Rejected", // 对方主动挂机，拒绝接听
	GATEWAY_ERROR : "Gateway_error", // 落地网关错误（没接SIM卡、卡欠费、卡异常等）
	UNKNOWN : "Unknown" // 其它原因
};


/**
 * 判断登录
 */
function checkLogin() {
	var type = $("#seatType").val();
	accountId = $("#channelId").val();
	ringtone = $("#ring-tone")[0];
	hangupSound = $("#hangupSound")[0];
	ringbacktone = $("#ringback-tone")[0];
	seatType = type;
	if (seatType == 1) {
		loginSeat();
	} else if (seatType == 2) {
		seatStatus = 2;
		controlCallBtn();
	} else if (seatType == 3) {
		initJanus();
	} else {
		seatStatus = 1;
		controlCallBtn();
	}
}
/**
 * 登录呼叫中心
 */
function loginSeat() {
	console.log("call.js...loginSeat()...")
	seatStatus = $("#seatStatus").val();
	var channelId = $("#channelId").val();
	var channelPwd = $("#channelPwd").val();
	var seatHost = $("#seatHost").val();
	var seatPort = $("#seatPort").val();
    console.log("call.js...loginSeat()...",
		"seatStatus="+seatStatus+
		",channelId="+channelId+
		",channelPwd"+channelPwd+
		",seatHost="+seatHost+
		",seatPort"+seatPort)
	if (seatStatus == "1") {
        console.log("call.js...loginSeat()...1")
		seatStatus = 9;
		controlCallBtn();
		callCenter = new xSoftphone({
			agentId : channelId, // 话机编号，由语音交换服务器提供
			password : channelPwd, // 注册密码，由语音交换服务器提供
			serverHost : seatHost, // 语音交换服务器IP地址
			serverPort : seatPort, // 语音交换服务器注册端口
			remoteAudio : "audio-remote", // HTML5 <audio>标签ID，用于播放语音
			localAudio : "audio-local", // HTML5 <audio>标签ID，用于播放语音
			onStatus : function(state, data, direction) {
                console.log("call.js...loginSeat()...2")
				// 话机状态回调处理函数
				// 参数state表示当前状态，data表示描述信息，direction会话方向
				if (PHONE_STATE.INVALID == state) {
                    console.log("call.js...loginSeat()...3")
					// 当前话机不可用，注册失败或者与语音交换服务器通信断开时触发。
					$("#callMobile").val("");
					//$("#callCustomerId").val("");
					//alert("登录失败");
					console.log("登录失败");
					seatStatus = 9;
					loginErrorCount += 1;
					if (loginErrorCount < 5) {
                        console.log("call.js...loginSeat()...4")
						reLogin();
					} else {
                        console.log("call.js...loginSeat()...5")
						alert("网络异常，请退出浏览器重新登录下！");
					}
				} else if (PHONE_STATE.IDLE == state) {
                    console.log("call.js...loginSeat()...6")
					// 当前话机空闲，注册成功或话机挂断资源释放完成后触发
					seatStatus = 2;
					/*if (Ext.getCmp("call_type") != null
						&& Ext.getCmp("call_type") != undefined) {
						Ext.getCmp("call_type").setValue("");
					}*/
					console.log("话机空闲");
				} else if (PHONE_STATE.RINGING == state) {
                    console.log("call.js...loginSeat()...7")
					if (SESSION_DIRECTION.INBOUND == direction) {
                        console.log("call.js...loginSeat()...8")
						// 呼入振铃，表示有电话呼入，此时参数data表示来电号码
						$("#callMobile").val(data);
						// openCallPhone(data);
						seatStatus = 4;
						/*if (Ext.getCmp("call_type") != null
							&& Ext.getCmp("call_type") != undefined) {
							Ext.getCmp("call_type").setValue("呼入");
						}*/
						try {
							ringtone.play();
						} catch (e) {} // 播放来电振铃
						console.log("1来电振铃");
					} else {
                        console.log("call.js...loginSeat()...9")
						// 外呼振铃，表示呼叫请求已经到达，等待对方摘机接听
						seatStatus = 3;
						/*if (Ext.getCmp("call_type") != null
							&& Ext.getCmp("call_type") != undefined) {
							Ext.getCmp("call_type").setValue("呼出");
						}*/
						try {
							ringbacktone.pause();
						} catch (e) {} // 播放呼出振铃
						console.log("1呼出振铃");
					}
                    console.log("call.js...loginSeat()...10")
				} else if (PHONE_STATE.ACCEPTED == state) {
                    console.log("call.js...loginSeat()...11")
					// 电话已接通，进入通话状态
					console.log("1电话已接通");
					seatStatus = 5;
					if (SESSION_DIRECTION.INBOUND == direction) {
                        console.log("call.js...loginSeat()...12")
						try {
							ringtone.pause();
						} catch (e) {}
					} else {
						try {
							ringbacktone.pause();
						} catch (e) {}
					}
					// addCallRecord();
				} else if (PHONE_STATE.TERMINATED == state) {
                    console.log("call.js...loginSeat()...13")
					// 电话挂断，呼出未接通提前挂断、呼出失败或接通后正常结束
					console.log("1电话已挂断");
					payHangupSound();
					var channelId = $("#channelId").val();
					if (SESSION_END_REASON.NORMAL == data) {
                        console.log("call.js...loginSeat()...14")
					} else if (SESSION_END_REASON.CANCEL == data) {
                        console.log("call.js...loginSeat()...15")
						//alert("外呼接通前主动挂断，请刷新或重新登录，如未解决请联系技术，原因[网络异常]");
					} else if (SESSION_END_REASON.INVALID_NUMBER == data) {
                        console.log("call.js...loginSeat()...16")
						//alert("当前呼叫为空号");
					} else if (SESSION_END_REASON.UNAVAILABLE == data) {
                        console.log("call.js...loginSeat()...17")
						//alert("暂时无法接通，请刷新或重新登录，如未解决请联系技术,原因[设备无应答]");
					} else if (SESSION_END_REASON.BUSY == data) {
                        console.log("call.js...loginSeat()...18")
						alert("用户忙，超时未接听");
					} else if (SESSION_END_REASON.REJECTED == data) {
                        console.log("call.js...loginSeat()...19")
						alert("对方主动挂机，拒绝接听");
					} else if (SESSION_END_REASON.GATEWAY_ERROR == data) {
						alert("当前坐席忙，请一分钟后重拨，连续三次出现请联系技术[" + channelId + "],原因[SIM卡异常]");
					} else if (SESSION_END_REASON.UNKNOWN == data) {
						alert("坐席异常，请刷新或重新登录，连续三次如未解决请联系技术，原因[设备异常]");
					}
					seatStatus = 2;
					//$("#callMobile").val("");
					//$("#callCustomerId").val("");
					if (SESSION_DIRECTION.INBOUND == direction) {
						try {
							ringtone.pause();
						} catch (e) {}
					}
				}
                console.log("call.js...loginSeat()...20")
				controlCallBtn();
			}
		});
        console.log("call.js...loginSeat()...21")
		callCenter.register();
        console.log("call.js...loginSeat()...22")
	} else if (seatStatus == "-1") {
        console.log("call.js...loginSeat()...23")
		// changeCallStatus("请换坐席");
		seatExpire = 1;
	}
}

//2019-10-15
function pausePayMusic(){
	try {
		ringtone.pause();
	} catch (e) {}
	try {
		ringbacktone.pause();
	} catch (e) {}
}

function payHangupSound() {
	try {
		console.log("播放挂断音");
		hangupSound.play();
		setTimeout(stopHangupSound, 1000);
	} catch (e) {}
}

function stopHangupSound() {
	try {
		console.log("停止挂断音");
		hangupSound.pause();
	} catch (e) {}
}

/**
 * 接听电话
 */
function acceptPhone() {
	if (seatType == 1) {
		callCenter.offhook();
	} else if (seatType == 3) {//2019-10-15
		doConnect();
	}
	seatStatus = 2;
	controlCallBtn();
	try {
		ringtone.pause();
	} catch (e) {}
	console.log("电话接听");

}
/**
 * 拨打电话
 *
 * @param customerId
 * @param phone
 */
function callPhone(customerId, phone, customerType) {
    console.log("callPhone",phone)
    if (seatStatus == 1 || seatStatus == 0) {
        //alert("您尚未分配坐席");
        console.log("您尚未分配坐席");
        loginSeat();
    } else if (seatStatus == 1) {
        //alert("您尚未登录呼叫中心");
        console.log("您尚未登录呼叫中心");
        loginSeat();
    } else if (seatExpire == 1) {
        alert("请更换坐席");
    } else if (seatStatus == 2) {
        $("#callCustomerId").val(customerId);
        $("#callMobile").val(phone);
        if (customerType) {
            $("#customerType").val(customerType);
        }
        if (seatType == 1) {
            callCenter.offhook("" + phone);
            try {
                ringbacktone.play();
            } catch (e) {}
            seatStatus = 3;
            controlCallBtn();
            // openCallPhone();
            // Ext.getCmp("call_type").setValue("呼出");
            console.log("电话呼出");
        } else if (seatType == 3) {//2019-10-15
            console.log("电话呼出:" + phone);
            doCall(phone);
            seatStatus = 3;
            controlCallBtn();
            // openCallPhone();
            // Ext.getCmp("call_type").setValue("呼出");
        } else if (seatType == 2) {
            // qhCall(accountId, phone);
        }
    } else if (seatStatus == 3) {
        alert("正在拨打电话中，禁止外呼");
    } else if (seatStatus == 4) {
        alert("有电话呼入中，禁止外呼");
    } else if (seatStatus == 5) {
        alert("正在通话中，禁止外呼");
    }



}

/**
 * 挂起电话
 */
function hangUpPhone() {
    console.log("index.call.js...hangUpPhone...1..")
	if (seatType == 1) {
        console.log("index.call.js...hangUpPhone...2..")
		seatStatus = 5;
		controlCallBtn();
		callCenter.onhook();
        console.log("index.call.js...hangUpPhone...3..")
	//phoneWin.close();
	} else if (seatType == 2) {
        console.log("index.call.js...hangUpPhone...4..")
		qhHangup(accountId);
        console.log("index.call.js...hangUpPhone...5..")
	} else if (seatType == 3) {//2019-10-15
        console.log("index.call.js...hangUpPhone...6..")
		seatStatus = 5;
		controlCallBtn();
		doHangup();
        console.log("index.call.js...hangUpPhone...7..")
	}
    console.log("index.call.js...hangUpPhone...8..")
}
function forceHangUpPhone() {
    seatStatus = $("#seatStatus").val();
    var channelId = $("#channelId").val();
    var channelPwd = $("#channelPwd").val();
    var seatHost = $("#seatHost").val();
    var seatPort = $("#seatPort").val();
	console.log("强制挂断电话",seatStatus);
	callCenter.unregister();
    console.log("w2");
	try {
        console.log("w3");
		ringtone.pause();
        console.log("w4");
	} catch (e) {
        console.log("w5");
	}
	try {
        console.log("w6");
		ringbacktone.pause();
        console.log("w7");
	} catch (e) {
        console.log("w8");
	}
    console.log("w9");
	loginSeat();
    console.log("w10");
}

function reLogin() {
	console.log("重新登录");
	try {
		ringtone.pause();
	} catch (e) {}
	try {
		ringbacktone.pause();
	} catch (e) {}
	callCenter.unregister();
	loginSeat();
}


/**
 * 更新呼叫状态
 * 
 * @param title
 */
function changeCallStatus(title) {
	if (seatExpire == 1) {
		title = "请换坐席";
		seatStatus = -1;
	}
	$("#topFrame").contents().find("#callSeatStatus").html(title);
	if (Ext.getCmp("call_status") != null
		&& Ext.getCmp("call_status") != undefined) {
		Ext.getCmp("call_status").setValue(title);
	}
	if (Ext.getCmp("call_mobile") != null
		&& Ext.getCmp("call_mobile") != undefined) {
		Ext.getCmp("call_mobile").setValue($("#callMobile").val());
	}
	if (Ext.getCmp("call_seatType") != null
		&& Ext.getCmp("call_seatType") != undefined) {
		if (seatType == 1) {
			Ext.getCmp("call_seatType").setValue("有吖");
		} else if (seatType == 3) {
			Ext.getCmp("call_seatType").setValue("滴石");
		} else if (seatType == 2) {
			var channelPwd = $("#channelPwd").val();
			var tip = "群鸿帐号：" + accountId + "  密码：" + channelPwd;
			Ext.getCmp("call_seatType").setValue("<span title='" + tip + "'>群鸿</span>");
		}
	}


}

/**
 * 当呼入时，打开相应的面板
 * 
 * @param customerId
 * @param signStatus
 * @param userId
 */
function openCustomer(customerId, signStatus, userId) {
	phoneWin.close();
	if (signStatus == 2 || signStatus == 3) {
		openFunItem({
			funViewXtype : "customermyView",
			funController : "yy.customer.controller.customermyController",
			funViewName : "yy.customer.view.customermyView"
		});
		openCustomerMain(customerId);
	} else {
		openFunItem({
			funViewXtype : "customerView",
			funController : "yy.customer.controller.customerController",
			funViewName : "yy.customer.view.customerView"
		})
		openCustomerMain(customerId);
	}
}

function addCallRecord() {
	var callCustomerId = $("#callCustomerId").val();
	if (callCustomerId != null && callCustomerId != "") {
		var url = "/customer/customer/call";
		var channelId = $("#channelId").val();
		Ext.Ajax.request({
			url : ctx + url,
			params : {
				id : callCustomerId,
				channelId : channelId
			},
			method : 'POST',
			timeout : 40000,
			success : function(form, action) {
				var resp = JSON.parse(form.responseText);
				var retCode = resp.retCode;
				if (retCode == 2) {
					seatExpire = 1;
				}
			},
			failure : function(form, action) {}
		});
	}

}

var callOutWin = null;

function opneCallOutWin() {
	if (callOutWin != null && callOutWin != undefined && callOutWin.show) {
		callOutWin.close();
	}
	;
	phoneWin.close();
	callOutWin = Ext.create("yy.app.view.callPhoneWin");
	callOutWin.show();
}

function callOutPhoneBtn() {
	var callNumber = Ext.getCmp('callOutNumber').value;
	if (callNumber != "" && callNumber.length > 5) {
		//if(isMobile(callNumber)){
		callOutWin.close();
		callPhone("", callNumber);

	//}else{
	//	alert("请输入11位手机号");
	//}
	} else {
		alert("请输入电话号码");
	}
}

function isMobile(str) {
	if (str == null || str == "")
		return false;
	var result = str.match(/^1[3|4|5|6|7|8|9][0-9]\d{4,8}$/);
	if (result == null)
		return false;
	return true;
}

/**
 * 打开电话面板
 * 
 * @param type
 * @param mobile
 * @param autoCustomerId 自动呼叫列表的客户ID，当呼叫的客户是从自动呼叫列表取出来的，则有值
 */
function openCallPhone(mobile, autoCustomerId) {
	if (phoneWin != null && phoneWin != undefined && phoneWin.show) {
		phoneWin.close();
	}
	phoneWin = Ext.create("yy.app.view.phoneWin");
	if (autoCustomerId) {
		$("#autoCustomerId").val(autoCustomerId);
	}

	var callCustomerGrid = Ext.getCmp('callCustomerGrid');
	if (mobile == null || mobile == "") {
		mobile = $("#callMobile").val();
	}
	$("#callMobile").val(mobile);
	var callCustomerId = $("#callCustomerId").val();
	var params = {
		mobile : mobile,
		id : callCustomerId
	};
	if (!callCustomerId) { //无客户ID时，隐藏通话日志区域
		var callLogPanel = Ext.getCmp('callLogPanel');
		callLogPanel.hide();
	}
	Ext.apply(callCustomerGrid.store.proxy.extraParams, params);
	callCustomerGrid.getStore().load({
		params : {
			start : 0,
			limit : 5
		}
	});
	if (callCustomerId == null || callCustomerId == "") {
		callCustomerId = -1;
	}
	params = {
		customerId : callCustomerId,
		userId : ""
	};
	var customerVisitGrid = Ext.getCmp('customerVisitGrid');
	Ext.apply(customerVisitGrid.store.proxy.extraParams, params);
	customerVisitGrid.getStore().load({
		params : {
			start : 0,
			limit : 3
		}
	});

	params = {
		mobile : mobile,
		userId : ""
	};
	var callRecordGrid = Ext.getCmp('callRecordGrid');
	Ext.apply(callRecordGrid.store.proxy.extraParams, params);
	callRecordGrid.getStore().load({
		params : {
			start : 0,
			limit : 3
		}
	});

	controlCallBtn();
	phoneWin.show();
}

/**
 * 控制呼叫按钮
 */
function controlCallBtn() {
    console.log("call.js...controlCallBtn()...",
        "seatStatus="+seatStatus)
	// 0-未分配坐席;1-未登录;2-空闲;3-呼出;4-呼入;5-接通
	var hangupFlag = false;
	var connectFlag = false;
	var callPhoneFlag = false;
	var callNextFlag = false;
	var saveLogFlag = false;
	var forceHangupFlag = false;
	if (seatStatus == 0) {
		hangupFlag = false;
		connectFlag = false;
		callPhoneFlag = false;
		callNextFlag = false;
		saveLogFlag = false;
		// changeCallStatus("未分配坐席");
		forceHangupFlag = false;
	} else if (seatStatus == 1) {
		hangupFlag = false;
		connectFlag = false;
		callPhoneFlag = false;
		callNextFlag = false;
		saveLogFlag = false;
		// changeCallStatus("未登录");
		forceHangupFlag = false;
	} else if (seatStatus == 2) {
		hangupFlag = false;
		connectFlag = false;
		callPhoneFlag = true;
		callNextFlag = true;
		saveLogFlag = true;
		// changeCallStatus("坐席空闲");
		forceHangupFlag = true;
	} else if (seatStatus == 3) {
		hangupFlag = true;
		connectFlag = false;
		callPhoneFlag = false;
		saveLogFlag = false;
		// changeCallStatus("电话呼出");
		forceHangupFlag = false;
	} else if (seatStatus == 4) {
		hangupFlag = true;
		connectFlag = true;
		callPhoneFlag = false;
		callNextFlag = false;
		saveLogFlag = false;
		forceHangupFlag = false;
		// changeCallStatus("电话呼入");
	} else if (seatStatus == 5) {
		hangupFlag = true;
		connectFlag = false;
		callPhoneFlag = false;
		callNextFlag = false;
		saveLogFlag = true;
		// changeCallStatus("通话中");
		forceHangupFlag = true;
	} else if (seatStatus == 6) {
		hangupFlag = true;
		connectFlag = false;
		callPhoneFlag = false;
		callNextFlag = false;
		saveLogFlag = true;
		// changeCallStatus("振铃中");
		forceHangupFlag = true;
	} else if (seatStatus == 9) {
		hangupFlag = false;
		connectFlag = false;
		callPhoneFlag = false;
		callNextFlag = false;
		saveLogFlag = false;
		// changeCallStatus("登录中~");
		forceHangupFlag = false;
	}
	/*if (Ext.getCmp('forceHangup') != null) {
		if (forceHangupFlag && seatType == 1) {
			Ext.getCmp('forceHangup').show();
		} else {
			Ext.getCmp('forceHangup').hide();
		}
	}*/
	/*if (Ext.getCmp('callPhoneBtn') != null) {
		if (callPhoneFlag && seatType == 1) {
			Ext.getCmp('callPhoneBtn').show();
		} else {
			Ext.getCmp('callPhoneBtn').hide();
		}
	}
	if (Ext.getCmp('connect') != null) {
		if (connectFlag) {
			Ext.getCmp('connect').show();
		} else {
			Ext.getCmp('connect').hide();
		}
	}
	if (Ext.getCmp('hangup') != null) {
		if (hangupFlag) {
			Ext.getCmp('hangup').show();
		} else {
			Ext.getCmp('hangup').hide();
		}
	}
	if (Ext.getCmp('callNext') != null) {
		if (callNextFlag && seatType == 1) {
			Ext.getCmp('callNext').show();
		} else {
			Ext.getCmp('callNext').hide();
		}
	}
	if (Ext.getCmp('saveLog') != null) {
		var callLogPanel = Ext.getCmp('callLogPanel');
		if (saveLogFlag) {
			var callCustomerId = $("#callCustomerId").val();
			if (callCustomerId) { //无客户ID时，隐藏通话日志区域
				callLogPanel.show();
				Ext.getCmp('saveLog').show();
			}
		} else {
			Ext.getCmp('saveLog').hide();
			callLogPanel.hide();
		}
	}*/
	console.log("controlCallBtn seatStatus=" + seatStatus);
}




function qhCall(accountId, phone) {
	Ext.Ajax.request({
		method : 'POST',
		url : ctx + '/api/call/qh/call',
		contentType : "application/json; charset=utf-8",
		jsonData : {
			accountId : accountId,
			phone : phone
		},
		dataType : 'json',
		async : false,
		success : function(response) {
			var result = JSON.parse(response.responseText).result;
			if (result == 0) {
				//Ext.MessageBox.alert("提示", "呼叫成功!");
				seatStatus = 5;
				controlCallBtn();
				openCallPhone();
				addCallRecord();
			} else {
				Ext.MessageBox.alert("提示", "呼叫失败,请检测是否有登录群鸿呼叫中心");
			}
		},
		failure : function(response, opts) {
			Ext.MessageBox.alert("提示", "获取失败!");
		}
	});
}

function qhHangup(accountId) {
	Ext.Ajax.request({
		method : 'POST',
		url : ctx + '/api/call/qh/hangup',
		contentType : "application/json; charset=utf-8",
		jsonData : {
			accountId : accountId,
		},
		dataType : 'json',
		async : false,
		success : function(response) {
			var result = JSON.parse(response.responseText).result;
			if (result == 0) {
				//Ext.MessageBox.alert("提示", "挂断成功!");
			} else {
				//Ext.MessageBox.alert("提示", "挂断失败!");
			}
			seatStatus = 2;
			controlCallBtn();
		},
		failure : function(response, opts) {
			Ext.MessageBox.alert("提示", "获取失败!");
		}
	});
}

//by cjianquan 2018/12/5
//呼叫下一家
function callNext() {
	Ext.Ajax.request({
		method : 'POST',
		url : ctx + '/customer/calledCustomer/getNextCustomer',
		contentType : "application/json; charset=utf-8",
		jsonData : {},
		dataType : 'json',
		async : false,
		success : function(response) {
			var record = JSON.parse(response.responseText).record;
			if (record) {
				$("#callCustomerId").val(record.customerId);
				$("#callMobile").val(record.mobile);
				openCallPhone('', record.id);
				callPhone(record.customerId, record.mobile);
			} else {
				Ext.MessageBox.alert("提示", "暂无可呼叫客户!");
			}
		},
		failure : function(response, opts) {
			Ext.MessageBox.alert("提示", "获取失败!");
		}
	});
}
//保存通话日志
function saveLog(_win) {
	var callCustomerId = $("#callCustomerId").val();
	if (callCustomerId) { //有客户ID才保存
		var content = _win.query("[name=content]")[0].getValue();
		//var intentionId = _win.query("[name=intentionId]")[0].getValue();
		//var intention = _win.query("[name=intention]")[0].getValue();
		var tag = _win.query("[name=tag]")[0].getValue();
		var accountType = _win.query("[name=accountType]")[0].getValue();
		var autoCustomerId = $("#autoCustomerId").val();
		var nextVisitTime = _win.query("[name=nextVisitTime]")[0].getValue();
		var customerType = $("#customerType").val();
		if (content || tag || accountType) {
			Ext.Ajax.request({
				method : 'POST',
				url : ctx + '/customer/calledCustomer/saveCallLog',
				contentType : "application/json; charset=utf-8",
				jsonData : {
					content : content,
					//intentionId : intentionId,
					//intention : intention,
					tag : tag,
					accountType : accountType,
					autoCustomerId : autoCustomerId,
					customerId : callCustomerId,
					nextVisitTime : nextVisitTime,
					customerType : customerType
				},
				dataType : 'json',
				async : false,
				success : function(response) {
					// JSON.parse(response.responseText).record
					Ext.MessageBox.alert("提示", "保存成功!");
					$("#autoCustomerId").val("");
					var callLogPanel = Ext.getCmp('callLogPanel');
					callLogPanel.hide();
				},
				failure : function(response, opts) {
					Ext.MessageBox.alert("提示", "保存失败!");
				}
			});
		} else {
			Ext.MessageBox.alert("提示", "通话日志尚无录入!");
		}
	} else {
		Ext.MessageBox.alert("提示", "无呼叫客户");
	}
}